package cn.tedu.order.controller;

import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.beans.factory.annotation.Autowired

import cn.tedu.common.pojo.Order
import cn.tedu.common.pojo.SysResult
import cn.tedu.order.service.OrderService
import java.util.List

@RestController
@RequestMapping(Array("order/manage"))
class OrderController {
  @Autowired
  private var orderService: OrderService = _

  // 查询我的订单
  @RequestMapping(Array("query/{userId}"))
  def queryMyOrders(@PathVariable userId: String):List[Order] = { orderService.queryMyOrders(userId) }

  // 新增订单
  @RequestMapping(Array("save"))
  def saveOrder(order: Order) = {
    try {
      orderService saveOrder order; SysResult ok
    } catch { case t: Exception => t.printStackTrace(); SysResult.build(201, "", null) }
  }

  // 删除订单
  @RequestMapping(Array("delete/{orderId}"))
  def deleteOrder(@PathVariable orderId: String) = {
    try {
      orderService deleteOrder orderId; SysResult ok
    } catch { case t: Exception => t.printStackTrace(); SysResult.build(201, "", null) }
  }
}